<?php

namespace util;

class Tulin
{

    private static $options = [

        'apikey' => '6999dd4aa62e4f55a2e02f23355a0806',
        'apiurl' => 'http://openapi.tuling123.com/openapi/api/v2',
        'secret' => '',
        'selfInfo' => [
        ],

    ];

    /**
     * 通过调用图灵机器人得到结果
     *
     * @param [type] $data  包含输入文本 用户ID
     * @return void
     */
    public static function getResult($data)
    {

        // switch ($data['type']) {
        //     case 'text':
        //         $reqType = 0;
        //         break;
        //     case 'images':
        //         $reqType = 1;
        //         break;
        //     case 'vioce':
        //         $reqType = 2;
        //         break;
        // }
        $reqType = $data['messType']; //消息类型 0:text 1:images 2:voice

        if ($reqType == 0) {
            $inputParams['input'] = 'inputText';
            $inputParams['param'] = 'text';
        } else if ($reqType == 1) {
            $inputParams['input'] = 'inputImage';
            $inputParams['param'] = 'url';
        } else if ($reqType == 2) {
            $inputParams['input'] = 'inputMedia';
            $inputParams['param'] = 'url';
        }

        $params = [
            'reqType' => $reqType,
            'perception' => [
                $inputParams['input'] => [
                    $inputParams['param'] => $data['content'],
                ],
                'selfInfo' => $data['selfInfo'],
            ],
            'userInfo' => [
                'apiKey' => self::$options['apikey'],
                'userId' => $data['userId'],
            ],
        ];

        $json = Curl::https_request(self::$options['apiurl'], json_encode($params));

        return $json;

    }

}
